<template>
  <el-row>
    <iframeDemo :url="url"  :height="height" ref="iframeDemo"/>
  </el-row>
</template>

<script>
import TopManu from "@/components/TopMenu";
import iframeDemo from "@/components/iframeDemo/index.vue"
import {iframeUrl} from "@/utils/server.js"
let that
export default {
  props:['url',"dataurl"],
  data(){
    return {
      url:"",
      height:"0"
    }
  },
  mounted(){
     that = this
     let data = that.dataurl
     console.log(that.dataurl)
     this.height = (document.body.clientHeight - 150) + 'px'
              setTimeout(function () {
            that.$nextTick(function () {
              let json = {

                id:data.id,
                type:data.type,
                name:data.name,
                token:localStorage.getItem("token"),
                category_id:data.category_id,
                dept_name:JSON.parse(localStorage.getItem("userInfo")).dept_name
              };
              this.$refs.iframeDemo.handleEmit(json);

            });
          }, 100);
// that.$router.push("/admin/caseList")

    //  this.url = `${iframeUrl}/#/caselist?id=${data.id}&type=${data.type}&name=${data.name}&token=${localStorage.getItem("token")}&category_id=${data.category_id}&dept_name=${JSON.parse(localStorage.getItem("userInfo")).dept_name}`
    //   window.addEventListener("message", function(data) {
    //   if(data.data.code == 200){
    //     that.$store.state.tagsView.visitedViews.forEach(item=>{
    //       if(item.name == "compile"){
    //         that.$store.state.tagsView.visitedViews.splice(that.$store.state.tagsView.visitedViews.findIndex(item => item.path === that.$route.path), 1)
    //         that.$router.push("/admin/caseList")
    //       }
    //     })
    //   }
    //   }, false);
  },
  watch:{
        dataurl(n){
          console.log('watch:', n)
           let data = n
        this.height = (document.body.clientHeight - 150) + 'px'
              setTimeout(function () {
            that.$nextTick(function () {
              let json = {

                id:data.id,
                type:data.type,
                name:data.name,
                token:localStorage.getItem("token"),
                category_id:data.category_id,
                dept_name:JSON.parse(localStorage.getItem("userInfo")).dept_name
              };
              this.$refs.iframeDemo.handleEmit(json);

            });
          }, 100);
        }
  } ,
  methods:{
    // 传值请求保存
    sendBtn(){
        let iframe = document.getElementById('iframe_demo');
        let json = {
          code:200
        };
        iframe.contentWindow.postMessage(json, '*');
    },
  },
  components:{
    iframeDemo,
    TopManu
  },
}
</script>

<style>

</style>
